//
//  80. 删除有序数组中的重复项 II.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/7/15.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation

class Solution80 {
    func removeDuplicates(_ nums: inout [Int]) -> Int {
        if nums.count < 2 {
            return nums.count
        }
        var slow = 2
        var fast = 2
        while fast < nums.count {
            // 一步一步向前走，
            if nums[slow - 2] != nums[fast] {
                nums[slow] = nums[fast]
                slow += 1
            }
            fast += 1
        }
        return slow
    }
    
    static func test() {
        var array = [0]
        let solution = Solution80()
        let result = solution.removeDuplicates(&array)
        
        print(array)
        print("个数\(result)")
    }
}
